package com.hc.music.controller;

import com.hc.music.common.R;
import com.hc.music.entity.Collect;
import com.hc.music.service.CollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("collect")
public class CollectController {
    @Autowired
    private CollectService collectService;

    @PostMapping("insert")
    public R addCollection(@RequestBody Collect collect) {
        collect.setCreateTime(new Date(System.currentTimeMillis()));
        collect.setSongListId(-1);
        return collectService.addCollection(collect);
    }

    @DeleteMapping("delete")
    public R deleteCollection(@RequestParam Integer userId, @RequestParam Integer songId) {
        return collectService.deleteCollect(userId, songId);
    }

    // 是否收藏歌曲
    @PostMapping("isCollected")
    public R isCollection(@RequestBody Collect collect) {
        return collectService.existSongId(collect);

    }

    // 返回的指定用户 ID 收藏的列表
    @GetMapping("selectByUserId")
    public R collectionOfUser(@RequestParam Integer userId) {
        return collectService.collectionOfUser(userId);
    }
}
